package 二叉树;

import common.TreeNode;

/**
 * @author tmh
 * @date 2024/8/21 20:47
 * @description
 */
public class T226翻转二叉树 {
    public TreeNode invertTree(TreeNode root) {
        //从上往下进行翻转--中左右
        if (root == null) {
            return null;
        }
        swap(root);
        invertTree(root.left);
        invertTree(root.right);
        return root;
    }

    private void swap(TreeNode root) {
        TreeNode temp = root.left;
        root.left = root.right;
        root.right = temp;
    }
}
